﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using SharedGenomics.Annotations;
using SharedGenomics.Workbench.Annotations;
using SharedGenomics.Workbench.Tests.TestObjects;

namespace SharedGenomics.Workbench.Tests.Annotations
{
    [TestClass]
    public class AggregateAnnotationRequestStageTests
    {
        private AggregateAnnotationRequestStage requestStage;

        [TestInitialize]
        public void Setup()
        {
            this.requestStage = new AggregateAnnotationRequestStage();
        }

        [TestMethod]
        public void ShouldAggregateTavernaAnnotationRequests()
        {
            AnnotationRequestContext pubContext = new AnnotationRequestContext(AnnotationKey.Publications, "rs001");
            AnnotationRequestContext geneContext = new AnnotationRequestContext(AnnotationKey.Gene, "rs001");
            AnnotationRequestContext keggPathwayContext = new AnnotationRequestContext(AnnotationKey.KeggPathway, "rs001");

            //stage should aggregate publications, pubMed, gene and kegg pathway annotations
            var traversalStrategy = new TestAnnotationRequestPipelineTraversalStrategy();
            this.requestStage.Process(pubContext, traversalStrategy);
            this.requestStage.Process(geneContext, traversalStrategy);
            this.requestStage.Process(keggPathwayContext, traversalStrategy);

            //strategy should only have been moved on once (for first request)
            Assert.AreEqual(1, traversalStrategy.MoveCount);

            //first request context (pubContext) should have its key updated to Taverna
            Assert.AreEqual(AnnotationKey.Taverna, pubContext.RequestKey);
        }

        [TestMethod]
        public void ShouldNotAggregateRequest()
        {
            AnnotationRequestContext context = new AnnotationRequestContext(AnnotationKey.GoogleSearch, "rs001");
            var traversalStrategy = new TestAnnotationRequestPipelineTraversalStrategy();

            this.requestStage.Process(context, traversalStrategy);

            //context should be unchanged and next stage called
            Assert.IsTrue(traversalStrategy.MovedNext);
            Assert.AreEqual(AnnotationKey.GoogleSearch, context.RequestKey);
        }
    }
}
